/**
  ******************************************************************************
  * @file    mbhost.c
  * @brief   This file provides code for the configuration
  *          of all used GPIO pins.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */
#include "mbhost.h"

uint16_t mbhost_read_coils_01(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, uint16_t num_of_coils)
{
  if(maxlen < 8){
    return 0;
  }

}

uint16_t mbhost_read_discrete_inputs_02(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, uint16_t num_of_disinputs)
{
  if(maxlen < 8){
    return 0;
  }
}

uint16_t mbhost_read_holding_registers_03(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, uint16_t num_of_regs)
{
  if(maxlen < 8){
    return 0;
  }
}

uint16_t mbhost_read_input_registers_04(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, uint16_t num_of_regs)
{
  if(maxlen < 8){
    return 0;
  }
}

uint16_t mbhost_write_single_coil_05(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, uint8_t state_of_coil)
{
  if(maxlen < 8){
    return 0;
  }
}

uint16_t mbhost_write_single_register_06(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, uint16_t data_of_reg)
{
  if(maxlen < 8){
    return 0;
  }
}

uint16_t mbhost_write_multiple_coils_15(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, const uint8_t *state_of_coils, uint16_t num_of_coils)
{
  uint8_t i;
  uint8_t num_of_bytes;
  uint8_t remainder;
  uint16_t integer;

  integer = num_of_coils / 8;
  remainder = num_of_coils % 8;
  if(remainder != 0){
    num_of_bytes = integer + 1;
  }else{
    num_of_bytes = integer;
  }

  if(maxlen < (num_of_bytes + 9)){
    return 0;
  }

  dest[0] = id;
  dest[1] = 0x0Fu;
  dest[2] = (uint8_t)(reg_addr >> 8);
  dest[3] = (uint8_t)reg_addr;
  dest[4] = (uint8_t)(num_of_coils >> 8);
  dest[5] = (uint8_t)num_of_coils;
  dest[6] = num_of_bytes;

  for(i=0; i<integer; i++)
  {

  }
}

uint16_t mbhost_write_multiple_registers_16(uint8_t *dest, uint16_t maxlen, uint8_t id, uint16_t reg_addr, const uint16_t *data_of_regs, uint16_t num_of_regs)
{
}